import { statisticDayTotalFlowTrendApi } from '../../api/statistic'
const initOption = () => {
  return {
    title: {
      text: '站场日累计流量走趋'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false
      }
    ],
    yAxis: {
      name: '流量/m³'
    }
  }
}
const apdaterOption = (dom) => {
  const titleFontSize = (dom.offsetWidth / 100) * 2
  return {
    title: {
      textStyle: {
        fontSize: titleFontSize
      }
    },
    legend: {
      itemWidth: titleFontSize,
      itemHeight: titleFontSize,
      itemGap: titleFontSize / 2
    },
    yAxis: {
      nameTextStyle: {
        fontSize: titleFontSize.value
      }
    }
  }
}
const dataOption = async (teamId) => {
  const { data: res } = await statisticDayTotalFlowTrendApi(teamId)
  const data = res.data
  const sourceLength = data.timeNameList.length
  const dataListLength = data.stationTotalFlowList.length
  const source = []
  const series = []
  const stations = []
  stations[0] = data.dataName
  for (let i = 0; i < dataListLength; i++) {
    stations.push(data.stationTotalFlowList[i].stationName)
    series.push({
      type: 'line',
      stack: data.dataName,
      label: {
        show: true,
        position: 'top'
      },
      areaStyle: {}
    })
  }
  source.push(stations)
  for (let i = 0; i < sourceLength; i++) {
    const dataList = []
    dataList.push(data.timeNameList[i].split(' ')[1])
    for (let j = 0; j < dataListLength; j++) {
      dataList.push(data.stationTotalFlowList[j].timeNodeTotalFlowList[i])
    }
    source.push(dataList)
  }
  return {
    dataset: {
      source: source
    },
    series: series,
    legend: {
      show: dataListLength > 0
    },
    tooltip: {
      show: dataListLength > 0
    }
  }
}

export { initOption, apdaterOption, dataOption }
